Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Math »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Convert a binary number to decimal number

Next topic

Add, subtract, multiply and division of two complex numbers

Quick search

Print a complex number and its real and imaginary partsΒΆ

Print a complex number and its real and imaginary parts.
Expected Output:
Complex Number: (2+3j)
Complex Number - Real part: 2.0
Complex Number - Imaginary part: 3.0
#Initialize a complex number
cn = complex(2, 3)

print("Complex Number: ", cn)
print("Complex Number - Real part: ", cn.real)
print("Complex Number - Imaginary part: ", cn.imag)

Output:

Complex Number:  (2+3j)
Complex Number - Real part: 2.0
Complex Number - Imaginary part: 3.0

See also

https://www.w3resource.com/python-exercises/math/python-math-exercise-32.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Math »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.